<template>
	<view class="all-box containers">

		<!-- 404页面 -->
		<view class="noData" v-if="netWorkType == 'none'">
			<noData @handle="refresh"></noData>
		</view>
		<view v-if="netWorkType != 'none'">
			<!--banner-->
			<view class="tui-banner-swiper scian-banner-wrap">
				<swiper :autoplay="true"   indicator-active-color="#69a4fe" :interval="5000"
					:duration="150" :circular="true" @change="bannerChange">
					<block>
						<!-- <block> -->
						<swiper-item :data-index="index" v-for="(item,index) in data.banner">
							<image @click="bannerToDetail(item)" mode="widthFix"
								class="scian-banner-img tui-slide-image" :src="item.src" />
						</swiper-item>
					</block>
				</swiper>
			</view>
			<!--detail-->
			<view class="dev-box marginleft15 marginright15">
				<view class="flex-box margin-bottom5">
					<view class="item">
						<view class="font18 font-bold margin-bottom5">健康数据</view>
					</view>
					<view class="item">
						<view @tap="toDevManage" class="btn-dev iconfont"><span style="margin-right: 10rpx;">&#xe6ff;</span>管理</view>
					</view>
				</view>
				<view class="flex-box margin-bottom20">
					<view @tap="navClickFun('pressure',1)" class="dev-list">
						<view class="bg-white padright15 border-radius8 padbottom15"
							style="margin-bottom: 24rpx;padding-left: 26rpx;">
							<view class="title">
								<view class="lf">血压</view>
								<view class="rg" v-if="data.bp!=''">
									<tui-tag padding="12rpx" size="small" style="font-weight: 500;font-size: 20rpx;" :type="data.bp.sp>=140?'danger':'green'">{{data.bp.sp>=140?'异常':'正常'}}</tui-tag>
								</view>
							</view>
							<view class="sub-title">
								<view class="lf" v-if="data.bp!=''">{{data.bp.create_time}}更新</view>
								<view class="lf" v-else>暂无数据</view>
								<!-- <view class="rg">
									10:25更新
								</view> -->
							</view>
							<view class="data-box  padtop10" v-if="data.bp!=''">
								<view class="lf">
									<view class="word">{{data.bp.sp}}/{{data.bp.dp}}</view>
								</view>
								<view class="rg">
									<view class="word">mmHg</view>
								</view>


							</view>
							<view class="data-box  padtop10" v-else>
								<view class="lf">
									<view class="word">-</view>
								</view>
							</view>
						</view>

					</view>

					<view @tap="navClickFun('mycuia',5)" class="dev-list">
						<view class="bg-white padright15 border-radius8 padbottom15"
							style="margin-bottom: 24rpx;padding-left: 26rpx;">
							<view class="title">
								<view class="lf">血糖</view>
								<view class="rg" v-if="data.glu!=''">
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="green" v-if="data.glu.status==1">正常</tui-tag>
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else-if="data.glu.status==2">异常</tui-tag>
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else="data.glu.status==3">异常</tui-tag>
								</view>
							</view>
							<view class="sub-title">
								<view class="lf" v-if="data.glu!=''">{{data.glu.create_time}}更新</view>
								<view class="lf" v-else>暂无数据</view>
								<!-- <view class="rg">
									10:25更新
								</view> -->
							</view>
							<view class="data-box  padtop10" v-if="data.glu!=''">
								<view class="lf">
									<view class="word">{{data.glu.glu}}</view>
								</view>
								<view class="rg">
									<view class="word">{{data.glu.unit_type_desc}}</view>
								</view>

							</view>
							<view class="data-box  padtop10" v-else>
								<view class="lf">
									<view class="word">-</view>
								</view>
							</view>
						</view>

					</view>
					<view @tap="navClickFun('sinocare',4)" class="dev-list" style="margin-top: 20rpx;">
						<view class="bg-white padright15 border-radius8 padbottom15"
							style="margin-bottom: 24rpx;padding-left: 26rpx;">
							<view class="title">
								<view class="lf">尿酸</view>
								<view class="rg" v-if="data.ua!=''">
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="green" v-if="data.ua.status==1">正常</tui-tag>
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else-if="data.ua.status==2">异常</tui-tag>

								</view>
							</view>
							<view class="sub-title">
								<view class="lf" v-if="data.ua!=''">{{data.ua.create_time}}更新</view>
								<view class="lf" v-else>暂无数据</view>
								<!-- <view class="rg">
									10:25更新
								</view> -->
							</view>
							<view class="data-box  padtop10" v-if="data.ua!=''">
								<view class="lf">
									<view class="word">{{data.ua.ua}}</view>
								</view>
								<view class="rg">
									<view class="word">{{data.ua!=''?'μmol/L':''}}</view>
								</view>

							</view>
							<view class="data-box  padtop10" v-else>
								<view class="lf">
									<view class="word">-</view>
								</view>
							</view>
						</view>

					</view>

				 <!--	<view @tap="navClickFun('mycuia',5)" class="dev-list">
						<view class="bg-white padright15 border-radius8 padbottom15"
							style="margin-bottom: 24rpx;padding-left: 26rpx;">
							<view class="title">
								<view class="lf">民康仪器-血糖</view>
								<view class="rg" v-if="data.glu!=''">
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="green" v-if="data.glu.status==1">正常</tui-tag>
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else-if="data.glu.status==2">异常</tui-tag>
									<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else="data.glu.status==3">异常</tui-tag>
								</view>
							</view>
							<view class="sub-title">
								<view class="lf" v-if="data.glu!=''">{{data.glu.create_time}}更新</view>
								<view class="lf" v-else>暂无数据</view>
								 <view class="rg">
									10:25更新
								</view>
							</view>
							<view class="data-box  padtop10" v-if="data.glu!=''">
								<view class="lf">
									<view class="word">{{data.glu.glu}}</view>
								</view>
								<view class="rg">
									<view class="word">{{data.glu.unit_type_desc}}</view>
								</view>
			
					</view>



					</view>
					-->
					<view @tap="navClickFun('lefu',5)" class="dev-list">
							<view class="bg-white padright15 border-radius8 padbottom15"
								style="margin-bottom: 24rpx;padding-left: 26rpx;">
								<view class="title">
									<view class="lf">体脂</view>
									<view class="rg" v-if="data.weightKg">
										<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="green" v-if="data.weightKg.status==1">正常</tui-tag>
										<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else-if="data.weightKg.status==2">偏低</tui-tag>
										<tui-tag size="small" padding="12rpx" style="font-weight: 500;font-size: 20rpx;" type="danger" v-else="data.weightKg.status==3">偏高</tui-tag>
									</view>
								</view>
								<view class="sub-title">
									<view class="lf" v-if="data.weightKg">{{data.weightKg.create_time}}更新</view>
									<view class="lf" v-else>暂无数据</view>
									<!-- <view class="rg">
										10:25更新
									</view> -->
								</view>
								<view class="data-box  padtop10" v-if="data.weightKg">
									<view class="lf">
										<view class="word">{{data.weightKg.num}}</view>
									</view>
									<view class="rg">
										<view class="word">kg</view>
									</view>

								</view>
								<view class="data-box  padtop10" v-else>
									<view class="lf">
										<view class="word">-</view>
									</view>
								</view>
							</view>

						</view>





				</view>
			</view>
			<!-- tip -->
			<!-- 精品优惠    开始 -->
			<!-- <view class="activity-box marginleft15 marginright15">
				<view class="mune-box  margin-bottom5">
					
					<view class="font18 font-bold margin-bottom5">精品优惠</view>
					<view class="sub-title">
						<view class="word">优选商品&nbsp&nbsp送惠到家</view>
					</view>
					
				</view>
				<view style="position:relative;" class="flex-box margin-bottom20" v-if="data.product_list.length>0">
					<view class="activity-list" @tap="toZpwWxApp(data.product_list[0].product_id)">
						<image style="width: 330rpx; height: 330rpx;border-radius: 24rpx;" :src="data.product_list[0].cover_image"></image>

					</view>
					<view class="activity-list">

						<view @tap="toZpwWxApp(data.product_list[1].product_id)" class="  padright15 border-radius8"
							style="   top:0px;position:absolute; width: 330rpx; height: 150rpx; ">
							<image class="img" style="width: 330rpx; height: 150rpx;border-radius: 24rpx;" :src="data.product_list[1].cover_image"></image>


						</view>
						<view @tap="toZpwWxApp(data.product_list[2].product_id)" class="  padright15 border-radius8"
							style=" margin-top: 30rpx; position:absolute; bottom: 0; width: 330rpx; height: 150rpx;">
							<image class="img" style="width: 330rpx; height: 150rpx;border-radius: 24rpx;" :src="data.product_list[2].cover_image"></image>

						</view>

					</view>


				</view>
				<view style="text-align: center; color: #CCCCCC;" v-else>暂无数据</view>
			</view> -->
			<!-- 精品优惠    结束 -->


		</view>
		<!-- 提示弹框 -->
		<tui-tips ref="toast"></tui-tips>

		<uni-popup-vlogin id="popupvLogin" ref="popupvLogin" type="bottom" />
	</view>

</template>

<script>
	import tuiTag from '@/components/tag/tag'
	import hxNavbar from '@/components/hx-navbar/hx-navbar'
	import {oss_host} from '@/config/config.js';
	import {
		mapGetters
	} from 'vuex';
	import Vue from 'vue'

	import store from '@/store/index.js';
	export default {


		components: {
			tuiTag,
			hxNavbar
		},
		computed: {
			//注册网络状态
			...mapGetters(['netWorkType', 'loginStatus']),
		},

		onShow: function(options) {
			this.getHome();
		},
		data() {
			return {

				// 图片链接站点
				OSS_HOST: oss_host,
				bannerIndex: 0,

				data: {
					bp: [],
					glu:[],
					product_list:[],
					banner: [],
					ua:[],

				},
				swiperHeight: 0,
				page_channel_type:1,
			}
		},
		methods: {
			toDevManage(){
				let _this = this;
				let path ='pages/dev_manage'
				_this.$refer.setVilit(path);
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				_this.$refer.toUrl(callback)
			},
			getHome() {
				let _this = this;
				var opt = {
					method: 'get',
					url: '/blutdruck_check/home',
					data:{
						page_channel_type:_this.page_channel_type,
						page_type:4
					},
					success: function(res) {
						if (res.status == 1) {
							_this.data.bp = res.data.bp;
							_this.data.glu = res.data.glu;
							_this.data.ua = res.data.ua;
							_this.data.weightKg = res.data.weightKg
							_this.data.product_list = res.data.product_list;
							_this.data.banner = res.data.banner.filter(function(cv) {
								return cv.estate == '1'

							});

						}
					}
				};

				_this.$service.GetApi(opt)
			},
			navClickFun(e,type) {
				let _this = this;
				console.log(type)
				if(type !=5){
					uni.showToast({
						icon:'none',
						title:'开发中'
						
					})
					retrun ;
				}
				let url = '';
				let obj = {
					pressure: '/packageHealthy/pages/device/blood-pressure/index',
					glucose: '/packageHealthy/pages/device/blood-glucose/index',
					sinocare: '/sinocare/index', //三诺
					scale:'/packageHealthy/pages/device/scale/index' ,
					mycuia:'/packageHealthy/pages/device/mycuia/index',
					lefu:'/packageWeight/pages/device/scale/index',//体脂称

				}
				let path = obj[e];
				console.log(path)
				_this.$refer.setVilit(path);
				let data = {
					product_type:type
				}
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				_this.$refer.toUrl(callback,data)
			},
			bannerToDetail(item) {

				let k = item.wx_url.lastIndexOf('=') + 1;
				let i = item.wx_url.lastIndexOf('?') - 1;
				let url = ';'
				if(i>0){
					 url = item.wx_url.substring(0, i + 1);
				}else{
					 url = item.wx_url;
				}

				let id = item.wx_url.substring(k, item.wx_url.length)
				console.log('url----',url)
				console.log('id----',id)

				let _this = this;
				_this.$refer.setVilit(url)
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				var data = {
					id: id
				}

				_this.$refer.toUrl(callback, data)
			},

			bannerChange: function(e) {
				this.bannerIndex = e.detail.current
			},
			//跳转滞品网小程序
			toZpwWxApp(id){
				uni.navigateToMiniProgram({
				  appId: 'wx7667b41e95e65e10',
				  path: 'pages/goods_details/index?id='+id,
				  success(res) {
				    // 打开成功
				  }
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "./main";
</style>
